package helper;

import java.util.Properties;

import javax.mail.*;
import javax.mail.internet.*;


public class Mail {
	
	public  void submitMail(String zhuti,String conten,String shoujianren) throws AddressException, MessagingException {
		
		String host = "smtp.126.com";
		String from = "nshf_10@126.com";
		String to = shoujianren;
		Properties props = System.getProperties();
		props.put("mail.smtp.host", host);
		props.put("mail.smtp.auth", "true");

		// Get session
		Session session = Session.getDefaultInstance(props, null);

		// Define message
		MimeMessage message = new MimeMessage(session);
			message.setFrom(new InternetAddress(from));
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
			message.setSubject(zhuti);
			message.setText(conten);
			message.saveChanges();

			// Send message
			Transport transport = session.getTransport("smtp");
			transport.connect(host, "nshf_10", "feishini");
			transport.sendMessage(message, message.getAllRecipients());
	}
	
	public static void main(String args[]){
		Mail m = new Mail();
		try {
			m.submitMail("zhuti", "neirong", "dahai118y@163.com");
		} catch (AddressException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
